﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shop.Core.Domain.Orders;
using System.Security.Principal;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Shop.Core.Domain.Customers
{
    [Serializable]
    public partial class Customer : BaseEntity<int>
    {
        IList<CustomerRule> rules = null;
        public Customer()
        {
            //System.ComponentModel.DataAnnotations.Validator.ValidateObject(
        }

        public virtual Profile Profile
        {
            get;
            set;
        }
        public virtual IList<CustomerRule> Rules
        {
            get
            {
                if (this.rules == null)
                {
                    this.rules = new List<CustomerRule>();
                }
                return this.rules;
            }
            set
            {
                this.rules = value;
            }
        }
        //private ICollection<ShoppingCartItem> _shoppingCartItems;

        [Required]
        public virtual string NickName
        {
            get;
            set;
        }

        [Required]
        public virtual string Email
        {
            get;
            set;
        }

        /// <summary>
        /// 仅仅为了在创建用户时使用。重建用户对象绝对不会查询出密码数据，如果要修改密码，需要别的业务实现。
        /// </summary>
        internal virtual string Password
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the customer has been deleted
        /// </summary>
        public virtual bool IsDeleted
        {
            get;
            set;
        }
        /// <summary>
        /// 是否是游客
        /// </summary>
        public virtual bool IsGuest
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the date and time of entity creation
        /// </summary>
        public virtual DateTime CreatedOn
        {
            get;
            set;
        }

        /// <summary>
        /// 最后登录时间
        /// </summary>
        public virtual DateTime LastLoginOn
        {
            get;
            set;
        }

        public static Customer CurrentCustomer
        {
            get
            {
                //System.Threading.Thread.CurrentPrincipal
                return HttpContext.Current.User.Identity as Customer;
            }
        }
    }
}